/**
 * 收款登记管理初始化
 */
var CollectBasicInformation = {
    id: "CollectBasicInformationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CollectBasicInformation.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '收款单号', field: 'collectId', visible: true, align: 'center', valign: 'middle'},
            {title: '审核状态', field: 'collectState', visible: true, align: 'center', valign: 'middle'},
            {title: '收款日期', field: 'collectDate', visible: true, align: 'center', valign: 'middle'},
            {title: '制单员', field: 'collectTradePerson', visible: true, align: 'center', valign: 'middle'},
            {title: '车号', field: 'collectCarId', visible: true, align: 'center', valign: 'middle'},
            {title: '驾驶员', field: 'collectCarDriver', visible: true, align: 'center', valign: 'middle'},
            {title: '电话', field: 'collectCarDriverTell', visible: true, align: 'center', valign: 'middle'},
            {title: '手机', field: 'collectCarDriverMobile', visible: true, align: 'center', valign: 'middle'},
            {title: '车次', field: 'collectCarNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '物流线路', field: 'collectRouteId', visible: true, align: 'center', valign: 'middle'},
            {title: '始发站', field: 'collectRouteStart', visible: true, align: 'center', valign: 'middle'},
            {title: '终点站', field: 'collectRouteEnd', visible: true, align: 'center', valign: 'middle'},
            {title: '运费', field: 'collectSumGoodsFreight', visible: true, align: 'center', valign: 'middle'},
            {title: '信息费', field: 'collectSumGoodsMessagefee', visible: true, align: 'center', valign: 'middle'},
            {title: '提货费', field: 'collectSumGoodsPickupCharge', visible: true, align: 'center', valign: 'middle'},
            {title: '中转站', field: 'collectRouteTransferStation', visible: true, align: 'center', valign: 'middle'},
            {title: '总费用', field: 'collectSumFee', visible: true, align: 'center', valign: 'middle'},
            {title: '本次收款', field: 'collectThisMoney', visible: true, align: 'center', valign: 'middle'},
            {title: '收费余额', field: 'collectUncollectMoney', visible: true, align: 'center', valign: 'middle'},
            {title: '收款方式', field: 'collectType', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'collectRemark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
CollectBasicInformation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CollectBasicInformation.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加收款登记
 */
CollectBasicInformation.openAddCollectBasicInformation = function () {
    var index = layer.open({
        type: 2,
        title: '添加收款登记',
        area: ['800px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/collectBasicInformation/collectBasicInformation_add'
    });
    this.layerIndex = index;
    layer.full(index);
};

/**
 * 打开查看收款登记详情
 */
CollectBasicInformation.openCollectBasicInformationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '收款登记详情',
            area: ['800px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/collectBasicInformation/collectBasicInformation_update/' + CollectBasicInformation.seItem.id
        });
        this.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 删除收款登记
 */
CollectBasicInformation.delete = function () {
    
    if (this.check()) {
    	var id = this.seItem.id
    	Feng.confirm("确认删除？",function(){
    		var ajax = new $ax(Feng.ctxPath + "/collectBasicInformation/delete", function (data) {
                Feng.success("删除成功!");
                CollectBasicInformation.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("collectBasicInformationId",id);
            ajax.start();
    	});
    }
};

/**
 * 查询收款登记列表
 */
CollectBasicInformation.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    CollectBasicInformation.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = CollectBasicInformation.initColumn();
    var table = new BSTable(CollectBasicInformation.id, "/collectBasicInformation/list", defaultColunms);
    table.setPaginationType("server");
    CollectBasicInformation.table = table.init();
});
